 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void login_Load(object sender, EventArgs e)
        {

        }
        //test
        //private void btlogin_Click(object sender, EventArgs e)
        //{
        //    Library.login lg = new Library.login();
        //    string username = txtuser.Text.Trim();
        //    string password = Querys.Md5(txtpass.Text.Trim());
        //    DataTable dtus = lg.getlogin(username, password);
        //    if (dtus != null && dtus.Rows.Count > 0)
        //    {
        //        DataUser.UserName = username;
        //        DataUser.RoleName = dtus.Rows[0]["quyen"].ToString();
        //        this.DialogResult = DialogResult.OK;
        //    }
        //    else
        //    {
        //        MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu");
        //    }
        //}

        //private void btquit_Click(object sender, EventArgs e)
        //{
        //    this.Close();
        //}

        private void txtuser_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                txtpass.Focus();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Library.login lg = new Library.login();
            string username = txtuser.Text.Trim();
            string password = Querys.Md5(txtpass.Text.Trim());
            DataTable dtus = lg.getlogin(username, password);
            if (dtus != null && dtus.Rows.Count > 0)
            {
                DataUser.UserName = username;
               //DataUser.UserName = "admin";
                DataUser.RoleName = dtus.Rows[0]["quyen"].ToString();
                //DataUser.RoleName = "all";
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
                this.Close();
        }

        private void txtpass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                SendKeys.Send("{enter}");
                this.AcceptButton = button1;
            }
        }
    }
}
